package com.lvyh.lightframe.tracer.core.context.threadlocal;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ContextHolder {
    private static ThreadLocal<String> contextHolder = new ThreadLocal<>();

    public static void set(String val) {
        contextHolder.set(val);
    }

    public static String get() {
        return contextHolder.get();
    }


    /*public static void main(String[] args) {
        contextHolder.set("main");
        System.out.println(contextHolder.get());
        ExecutorService executorService = Executors.newFixedThreadPool(4);
        Thread thread = new Thread(new Runnable() {
            public void run() {
                System.out.println("do async task.");
                System.out.println(contextHolder.get());
            }
        });
        executorService.submit(thread);//contextHolder.get()=null

        DelegatingContextRunnable delegatingContextRunnable = new DelegatingContextRunnable(thread);
        executorService.submit(delegatingContextRunnable);//contextHolder.get()=main

        ExecutorHelper.execute(thread);//contextHolder.get()=main
    }*/
}
